package bb.lanxing.mvp.presetner;

import org.json.JSONException;
import org.json.JSONObject;

import bb.lanxing.mvp.presetner.i.IGetAuthCodeModel;
import bb.lanxing.network.MyHttpClient;
import bb.lanxing.network.NetSubscribe;
import okhttp3.Call;
import rx.Observable;
import rx.schedulers.Schedulers;

public class GetAuthCodeModelImpl implements IGetAuthCodeModel {
    @Override
    public Observable<JSONObject> getAuthCode(String str, int i, int i2, long j) {
        Call requestAuthcode = MyHttpClient.requestAuthcode(str, i, i2, j);
        return Observable.create(new NetSubscribe(requestAuthcode)).subscribeOn(Schedulers.io()).flatMap(str2 -> {
            try {
                return Observable.just(new JSONObject(str2));
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
        });
    }

    @Override
    public Observable<Long> getServiceTime() {
//        return Observable.create(new NetSubscribe(BiciHttpClient.requestServiceTime())).subscribeOn(Schedulers.io()).flatMap(str -> {
//            long j;
//            try {
//                j = new JSONObject(str).getLong("time_unix");
//            } catch (JSONException e) {
//                e.printStackTrace();
//                j = 0;
//            }
//            return Observable.just(Long.valueOf(j));
//        });
        return null;
    }
}
